/*
  Name: DeadProxyClientContainer.cpp
  Copyright:
  Author: Carl Chatfield
  18/02/08 14:03
  Description: Stores Containers Info
*/

#include "DeadProxyClientContainer.h"

ContainerManager::ContainerManager()
{
    memset(Containers, 0, sizeof(Container) * 16);
}

void ContainerManager::OpenContainer(unsigned int index, unsigned short icon, char * title, unsigned int maxSize, bool HasParent)
{
    Containers[index].IsOpen = true;
    Containers[index].HasParent = HasParent;
    Containers[index].icon = icon;
    strcpy(Containers[index].title, title);
    Containers[index].MaxSize = maxSize;
    Containers[index].ItemCount = 0;
    delete title;
}

void ContainerManager::CloseContainer(unsigned int index)
{
    Containers[index].IsOpen = false;
}

void ContainerManager::InitAddItem(unsigned int index, Thing * item)
{
    memcpy(&Containers[index].Items[Containers[index].ItemCount], item, sizeof(Thing));
    Containers[index].ItemCount++;
    delete item;
}

void ContainerManager::AddItem(unsigned int index, Thing * item)
{
    memcpy(&Containers[index].Items[1], &Containers[index].Items[0], sizeof(Thing) * Containers[index].ItemCount);
    memcpy(&Containers[index].Items[0], item, sizeof(Thing));
    Containers[index].ItemCount++;
    delete item;
}

void ContainerManager::RemItem(unsigned int index, unsigned int slot)
{
    memcpy(&Containers[index].Items[slot], &Containers[index].Items[slot + 1], sizeof(Thing) * (Containers[index].ItemCount - 1 - slot));
    Containers[index].ItemCount--;
}

void ContainerManager::RepItem(unsigned int index, unsigned int slot, Thing * item)
{
    memcpy(&Containers[index].Items[slot], item, sizeof(Thing));
    delete item;
}

